package com.design.pattern.structure.conposite.general;

import java.util.ArrayList;
import java.util.List;

public class Composite extends Component{
    private List<Component> componentList;

    public Composite(String name) {
        super(name);
        this.componentList = new ArrayList<>();
    }


    @Override
    public String operation() {
        StringBuilder sb = new StringBuilder();
        for(Component component : componentList) {
            sb.append("\n");
            sb.append(component.operation());
        }
        return sb.toString();
    }


    @Override
    public boolean addChild(Component component) {
        this.componentList.add(component);
        return true;
    }

    @Override
    public boolean removeChild(Component component) {
        return super.removeChild(component);
    }

    @Override
    public Component getChild(int index) {
        return super.getChild(index);
    }
}
